package com.example.parttimejob.controller;

import com.example.parttimejob.mapper.StoreMapper;
import com.example.parttimejob.pojo.entity.Merchants;
import com.example.parttimejob.pojo.entity.dto.*;
import com.example.parttimejob.pojo.entity.vo.*;
import com.example.parttimejob.service.StoreService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/Store")
@CrossOrigin
public class StoreController {

    @Autowired
    private StoreService storeService;

    //商户注册
    @PostMapping("/registStore/{merchantUsername}/{passwd}")
    public String registStore(@PathVariable String merchantUsername,@PathVariable String passwd)
    {
//        System.out.println(merchantUsername);
//        System.out.println(passwd);
        return storeService.registStore(merchantUsername,passwd);
    }

    //商户登录
    @GetMapping("/loginStore/{merchantUsername}/{passwd}")
    public int loginStore(@PathVariable String merchantUsername,@PathVariable String passwd)
    {
        return storeService.loginStore(merchantUsername,passwd);
    }


    //根据商户id查询商户信息
    @GetMapping("/getById/{id}")
    public Merchants getById(@PathVariable Integer id)
    {
      return storeService.getById(id);
    }

   //判断商家是否实名
    @GetMapping("/selectStoreStatus/{merchantId}")
    public String SelectStoreStatus(@PathVariable Integer merchantId)
    {
        return storeService.SelectStoreStatus(merchantId);
    }


    //商户实名认证
    @PostMapping("/IdeafiStore")
    public String IdeafiStore(@RequestBody MerchantsDto merchantsDto)
    {
//        System.out.println(1);
//        System.out.println(merchantsDto.getMerchantName());
//        System.out.println(merchantsDto.getMerchantName());
    return storeService.IdeafiStore(merchantsDto);
    }

    //商户首先查询信息再修改
    @GetMapping("/SelectModify/{merchantId}")
    public MerchantsModifyVo SelectModify(@PathVariable Integer merchantId){
        return storeService.SelectModify(merchantId);
    }
//    商户修改信息
    @PutMapping("/ModifyStore")
    public String ModifyStore(@RequestBody MerchantsModifyDto merchantsModifyDto){
     return  storeService.ModifyStore(merchantsModifyDto);
    }

    //发布兼职
    @PostMapping("/Create")
    public String Create(@RequestBody PartTimeJobsDto partTimeJobsDto)
    {
     return storeService.Create(partTimeJobsDto);
    }

    //查询所有兼职信息
    @GetMapping("/PartJob/{merchantId}")
    public List<PartTimeJobsVo> PartJob(@PathVariable Integer merchantId)
    {
        return storeService.PartJob(merchantId);
    }



    //商家审核用户(聘用或不聘用)或者解雇 管理兼职界面
    @PutMapping("/CheckUser")
    public String CheckUser(@RequestBody CheckUserDto checkUserDto)
    {
        return storeService.CheckUser(checkUserDto);
    }

    //商家删除兼职未请求的信息
    @DeleteMapping("/DeleteJob/{jobId}")
    public String DeleteJob(@PathVariable Integer jobId)
    {
        return storeService.DeleteJob(jobId);
    }

    //修改之前查询兼职信息 //根据兼职表id查询信息
    @GetMapping("/SelectModifyJob/{jobId}")
    public PartTimeJobsModifyVo SelectModifyJob(@PathVariable Integer jobId)
    {
        return storeService.SelectModifyJob(jobId);
    }

    //修改兼职信息(待请求的)
    @PutMapping("/ModifyJob")
    public String ModifyJob(@RequestBody PartTimeJobsModifyDto partTimeJobsModifyDto)
    {
        return storeService.ModifyJob(partTimeJobsModifyDto);
    }

    //商家评论录取或解雇的兼职（通过兼职表） 管理兼职界面
    @PostMapping("/AddReview")
    public String AddReview(@RequestBody AddReviewDto addReviewDto)
    {
        return storeService.AddReview(addReviewDto);
    }


    //查询所有的商铺号
    @GetMapping("/ShowForUser")
    public List<ShowForUser> ShowForUser()
    {
        return storeService.ShowForUser();
    }


    @GetMapping("/SearchStore/{category}")
    public List<ShowForUser> SearchStore(@PathVariable String category)
    {
      return storeService.SearchStore(category);
    }


@Autowired
    StoreMapper storeMapper;

    @GetMapping("/store-including/{username}")
    public List<Merchants> getUsersIncludingUsername(@PathVariable String username) {
        List<Merchants> allUsers = storeMapper.selectList(null);
        return allUsers.stream()
                .filter(merchants -> merchants.getMerchantName().equals(username))
                .collect(Collectors.toList());
    }


}
